package com.zzptc.easyshop.servlet;

import com.zzptc.easyshop.dao.UserDao;
import com.zzptc.easyshop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name = "RegServlet")
public class RegServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       PrintWriter pw=response.getWriter();
     //   pw.print("hello");
        //接受用户请求
        String username= request.getParameter("userName");
        String password= request.getParameter("password");
        pw.print(username+",hello");

        UserDao userDao=new UserDao();
        Users user=new Users();
        user.setEu_user_id("6");
        user.getEu_user_name(username);
        user.setEu_password(password);
        boolean b=false;
        try {
            b=userDao.insert(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if(b){
            System.out.println("succ");
        }else{
            System.out.println("error");
        }

    }
}
